package com.koicarp.university.graduate.web.controller.dataCompare;

import com.koicarp.university.graduate.service.service.graduateInfoManage.IGraduateStatusService;
import com.koicarp.university.graduate.service.service.report.IReportService;
import com.koicarp.university.graduate.service.service.report.ISchoolReportService;
import com.koicarp.university.graduate.service.vo.dataCompare.EmployRateVo;
import com.koicarp.university.graudate.common.constant.BaseConstant;
import com.koicarp.university.graudate.common.utils.UniversityResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @auther liutao
 * @Date 2020-11-29 10:41:13
 */
@Slf4j
@RestController
@RequestMapping("dataCompare")
@RequiredArgsConstructor
@Api(tags = "数据对比控制层")
public class DataCompareController {
    private final IGraduateStatusService graduateStatusService;

    private final IReportService reportService;

    private final ISchoolReportService schoolReportService;

    @PostMapping(value = "getEmployRate")
    @ApiOperation(value = "（数据对比-就业率）",notes = "分学院，班级，专业维度")
    public UniversityResponse getEmployRate(@RequestBody EmployRateVo employRateVo){
        UniversityResponse response=null;
        try{
            response = graduateStatusService.getEmployRate(employRateVo);
        }catch (Exception e){
            log.error("查询",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping(value = "getSelectOption")
    @ApiOperation(value = "查询条件",notes = "分学院，班级，专业维度")
    public UniversityResponse getSelectOption(){
        UniversityResponse response=null;
        try{
            response = graduateStatusService.getSelectOption();
        }catch (Exception e){
            log.error("查询",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping(value = "getSalaryByYear")
    @ApiOperation(value = "最低，最高，平均薪水分布图",notes = "分学院，班级，专业维度")
    public UniversityResponse getSalaryByYear(@RequestBody EmployRateVo employRateVo){
        UniversityResponse response=null;
        try{
            response = reportService.getSalaryByYear(employRateVo);
        }catch (Exception e){
            log.error("查询",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
    @PostMapping(value = "getSchoolByType")
    @ApiOperation(value = "学校相关问卷分布图",notes = "分四个维度")
    public UniversityResponse getSchoolByType(@RequestBody EmployRateVo employRateVo){
        UniversityResponse response=null;
        try{
            if (employRateVo.getSchoolReportType().equals("STAISFY_LEAN")){
                response = schoolReportService.countLeanByYear(employRateVo);
            }
            if (employRateVo.getSchoolReportType().equals("STAISFY_CLASS")){
                response = schoolReportService.countClassByYear(employRateVo);
            }
            if (employRateVo.getSchoolReportType().equals("ACTIVITY")){
                response = schoolReportService.countActivityByYear(employRateVo);
            }
            if (employRateVo.getSchoolReportType().equals("ENOUGH_STUDY")){
                response = schoolReportService.countStudyByYear(employRateVo);
            }
        }catch (Exception e){
            log.error("查询",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }


    @PostMapping(value = "getFiveYear")
    @ApiOperation(value = "获取近五年")
    public UniversityResponse getFiveYear(){
        UniversityResponse response=null;
        try{
            response = schoolReportService.getFiveYear();
        }catch (Exception e){
            log.error("查询",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }

    @PostMapping(value = "getAveSalaryByAddress")
    @ApiOperation(value = "数据对比-地图分布",notes = "分学院，班级，专业，平均薪资")
    public UniversityResponse getAveSalaryByAddress(@RequestBody EmployRateVo employRateVo){
        UniversityResponse response=null;
        try{
            response = reportService.getAveSalaryByAddress(employRateVo);
        }catch (Exception e){
            log.error("查询",e);
            response = new UniversityResponse();
            response.code(BaseConstant.RESPONSE_CODE_FAILED_500);
            response.message(BaseConstant.RESPONSE_MESSAGE_OPR_FAILED);
        }
        return response;
    }
}
